package com.wt.service;


import com.sun.org.apache.xpath.internal.operations.Or;
import com.wt.dao.OrderDao;
import com.wt.entity.Order;

import java.sql.SQLException;
import java.util.List;

public class OrderService {
    OrderDao orderDao = new OrderDao();

    public List<Order> selectAllOrder(String name) throws SQLException {
        List<Order> orders =  orderDao.selectAllOrder(name);
        if (orders == null || 0 == orders.size()){
            return null;
        }
        return addImageUrl(orders);
    }

    public Boolean updateOrderStater(Integer orderId, Integer stater) throws SQLException {
        return orderDao.updateOrderStater(orderId,stater);
    }

    public Boolean addOrder(Order order) throws SQLException {
       return orderDao.addOrder(order);
    }

    public Boolean delOrder(Integer orderId) throws  SQLException{
        return orderDao.delOrder(orderId);
    }
    //给图片追加服务器地址
    private List<Order> addImageUrl(List<Order> orders){
        for (int i = 0; i < orders.size(); i++){
            orders.get(i).setScenicImage("http://localhost:8188" + orders.get(i).getScenicImage());
        }
        return orders;
    }
}
